home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / Scian.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  13KB  |  416 lines

  1. /*Scian.h
  2.   Standard header for scian.
  3.   Eric Pepke
  4.   February 9, 1990
  5. */
  6.  
  7. #include "machine.h"
  8.  
  9. /*If it's computation only, no interaction or graphics.*/
  10. #ifdef COMPONLY
  11. #undef GRAPHICS
  12. #undef INTERACTIVE
  13. #endif
  14.  
  15. #define GODLIKE 
  16.  
  17. #ifdef RELEASE
  18. #undef SOCKETS
  19. #undef GODLIKE
  20. #endif
  21.  
  22. #ifdef GODLIKE
  23. #define PARANOID
  24. #endif
  25.  
  26. #ifndef GRAPHICS
  27. /*No graphics features at all*/
  28. #undef WINDOWS4D
  29. #undef MENUS4D
  30. #undef FONTS4D
  31. #undef CURSORS4D
  32. #undef IRISNTSC
  33. #undef GL4D
  34. #undef INTERWINDRAG
  35. #undef NOHIDEFRAME
  36. #undef GRAPHOBJ
  37. #endif
  38.  
  39. /*Yes, signals*/
  40. #if 0
  41. #define SIGNALS
  42. #endif
  43.  
  44. #ifdef STDLIB
  45. #include <stdlib.h>
  46. #endif
  47. #include <ctype.h>
  48. #include <sys/types.h>
  49. #ifdef INTERACTIVE
  50. #include <device.h>
  51. #include <fcntl.h>
  52. #endif
  53. #ifdef GRAPHICS
  54. #ifdef FONTS4D
  55. #include <fmclient.h>
  56. #endif
  57. #include <gl.h>
  58. #if MACHINE == IRIS4D
  59. #include <gl/addrs.h>
  60. #include <gl/cg2vme.h>
  61. #include <gl/get.h>
  62. #endif
  63. #else
  64. typedef float Matrix[4][4];
  65. #endif
  66. #ifdef MALLOCH
  67. #include <malloc.h>
  68. #else
  69. extern void *malloc();
  70. #endif
  71. #include <math.h>
  72. #ifdef SOCKETS
  73. #include <netdb.h>
  74. #include <netinet/in.h>
  75. #endif
  76. #include <stdio.h>
  77. #include <string.h>
  78. #include <values.h>
  79. #include <sys/dir.h>
  80. #include <sys/file.h>
  81. #include <sys/signal.h>
  82. #if MACHINE == RS6000
  83. #include <sys/machine.h>
  84. #endif
  85. #include <sys/param.h>
  86. #ifdef SOCKETS
  87. #include <sys/socket.h>
  88. #endif
  89. #include <sys/stat.h>
  90. #include <sys/times.h>
  91. #include <sys/time.h>
  92. #if MACHINE == RS6000
  93. #include <time.h>
  94. #endif
  95. #ifdef TERMIO
  96. #include <termio.h>
  97. #endif
  98.  
  99. #ifndef INTERACTIVE
  100. #undef DIALBOX
  101. #endif
  102.  
  103. #ifndef DIAL0
  104. #undef DIALBOX
  105. #endif
  106.  
  107. #ifndef STDLIB
  108. double strtod();
  109. #endif
  110.  
  111. typedef int Bool;            /*Our boolean stuff*/
  112. #define true 1
  113. #define false 0
  114.  
  115. /*C Variable types*/
  116. typedef float real;
  117. typedef real Quaternion[4];
  118.  
  119. /*Bits for flags*/
  120. #define PLAINOBJECT     0        /*Plain object*/
  121. #define REALARRAY    1        /*Array of real values*/
  122. #define STRING        2        /*Single string value*/
  123. #define INTEGER        3        /*Single integer value*/
  124. #define REAL        4        /*Single real value*/
  125. #define LIST        5        /*List of things*/
  126. #define PALETTE        6        /*Palette of colors*/
  127. #define OT_SHORTARRAY    7        /*Short array*/
  128. #define WINDOW        8        /*Window*/
  129. #define PICTURE        9        /*Picture of graphical objects*/
  130. #define OBJECTARRAY    10        /*Array of objects*/
  131. #define CONNECTION    11        /*Socket connection*/
  132. #define SYMBOL        12        /*Symbol*/
  133. #define OT_GEOMETRY    13        /*Geometry*/
  134. #define OT_BYTEARRAY    14        /*Byte array*/
  135. #define OT_POINTERARRAY    15        /*Pointer array*/
  136. #define OT_POINTER    16        /*Pointer*/
  137. #define HIGHESTFLAG    17        /*Highest flag*/
  138.  
  139. #define ISOBJECT    PLAINOBJECT    /*Kludge for backward compat.*/
  140.  
  141. #define OBJTYPEFLAGS    0xFF        /*Object type flags*/
  142. #define OBJTYPE(flags)    ((flags) & 0xFF)
  143. #define SETOBJTYPE(flags, type)    (flags) = ((flags) & ~OBJTYPEFLAGS) | type
  144.  
  145. /*Object predicate, returns true iff theObj is an object*/
  146. #define IsObject(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == PLAINOBJECT))
  147. #define IsArray(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == REALARRAY))
  148. #define IsByteArray(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == OT_BYTEARRAY))
  149. #define IsRealArray(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == REALARRAY))
  150. #define IsObjArray(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == OBJECTARRAY))
  151. #define IsShortArray(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == OT_SHORTARRAY))
  152. #define IsList(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == LIST))
  153. #define IsReal(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == REAL))
  154. #define IsString(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == STRING))
  155. #define IsInt(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == INTEGER))
  156. #define IsSymbol(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == SYMBOL))
  157. #define IsPointer(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == OT_POINTER))
  158. #define IsPalette(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == PALETTE))
  159. #define IsMatrix(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == MATRIX))
  160. #define IsWindow(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == WINDOW))
  161. #define IsPicture(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == PICTURE))
  162. #define IsGeometry(theObj) ((theObj) && (OBJTYPE(((ThingPtr)(theObj)) -> flags) == OT_GEOMETRY))
  163.  
  164. /*NIL pointer, define so that it can cast to any pointer*/
  165. #define NIL ((void *) 0)
  166.  
  167. #define CopyVar(d, s, v) SetVar(d, v, GetVar(s, v))
  168.  
  169. /*newp operator*/
  170. #define newp(t)    ((t *) Alloc(sizeof(t)))
  171.  
  172. /*running variable, true iff running*/
  173. extern int running;
  174.  
  175. /*running remote(ly) variable, true if running remotely*/
  176. extern Bool runningRemote;
  177.  
  178. /*Demo mode, make text bigger and fatter*/
  179. extern Bool demoP;
  180.  
  181. /*Use selects in scripts*/
  182. extern Bool scriptSelectP;
  183.  
  184. /*Abort on script error*/
  185. extern Bool abortScriptP;
  186.  
  187. /*Temporary string*/
  188. #define TEMPSTRSIZE    4000
  189. extern char tempStr[TEMPSTRSIZE + 1];
  190.  
  191. /*Fonts*/
  192. #define TITLEFONT    1        /*Font for big titles*/
  193. #define SUBTITLEFONT    2        /*Subtitle font*/
  194. #define ICONBEGFONTS    3        /*Beginning of icon fonts*/
  195. #if 0
  196. #define ICONFOREFONT    3        /*Font for icon foreground*/
  197. #define ICONBACKFONT    4        /*Font for icon background*/
  198. #define ICONSHADOWFONT    5        /*Font for icon shadow*/
  199. #endif
  200.  
  201. /*Cursors*/
  202. #define ARROWCURSOR    0        /*Arrow cursor*/
  203. #define WATCHCURSOR    1        /*Watch cursor*/
  204. #define IBEAMCURSOR    2        /*I-beam cursor*/
  205. #define QUESTIONCURSOR    3        /*Question mark cursor*/
  206. #define ICONCURSOR    4        /*Icon cursor*/
  207.  
  208. /*Class IDs*/
  209. #define CLASS_ICON        0    /*Icon class*/
  210. #define CLASS_CORRAL        1    /*Corral class*/
  211. #define CLASS_VISWINDOW        2    /*Vis window class*/
  212. #define CLASS_LIGHT        3    /*Class of a light*/
  213. #define CLASS_CLOCK        4    /*Class of a clock*/
  214. #define CLASS_OBSERVER        5    /*Class of an observer*/
  215. #define CLASS_RENDERER        6    /*Class of a renderer*/
  216. #define CLASS_TIMEDOBJ        7    /*Timed object class*/
  217. #define CLASS_VISOBJ        8    /*Vis object class*/
  218. #define CLASS_PANEL        9    /*Panel class*/
  219. #define CLASS_DATASET        10    /*Dataset class*/
  220. #define CLASS_FILE        11    /*File class*/
  221. #define CLASS_TEXTBOX        12    /*Text box class*/
  222. #define CLASS_SPACE        13    /*Space class*/
  223. #define CLASS_DIALOG        14    /*Dialog class*/
  224. #define CLASS_FILEREADER    15    /*File reader class*/
  225. #define CLASS_RECORDER        16    /*Recorder*/
  226. #define CLASS_SNAPSHOT        17    /*Snapshot*/
  227. #define CLASS_SEQUENCE        18    /*Sequence class*/
  228. #define CLASS_MENU        19    /*Class of menus*/
  229. #define CLASS_ACTION        20    /*Class of menu actions*/
  230. #define N_CLASS_IDS        21    /*Total # of class id's*/
  231.  
  232. /*Is icon predicate*/
  233. #define IsIcon(icon) IntVarEql(icon, CLASSID, CLASS_ICON)
  234.  
  235. extern real missingData;        /*Missing data*/
  236. extern real plusInf, minusInf;        /*Plus and minus infinity*/
  237. #define PLUSINF        (plusInf)    /*Plus infinity*/
  238. #define MINUSINF    (minusInf)    /*Minus infinity*/
  239.  
  240. #define SCIANDATE       "November 6, 1993" 
  241. #define SCIANVERSION    "Version 0.851"
  242. #define AUTOLOG                /*Automatically log for error tracking*/
  243.  
  244. /*Screen sizes*/
  245. #ifdef XMAXSCREEN
  246. #define CSCRWIDTH    XMAXSCREEN
  247. #define CSCRHEIGHT    YMAXSCREEN
  248. #define VSCRWIDTH    XMAX170
  249. #define VSCRHEIGHT    YMAX170
  250. #else
  251. #define CSCRWIDTH    1280
  252. #define CSCRHEIGHT    1024
  253. #define VSCRWIDTH    649
  254. #define VSCRHEIGHT    484
  255. #endif
  256.  
  257. #define SCRWIDTH scrWidth
  258. #define SCRHEIGHT scrHeight
  259. extern int scrWidth, scrHeight;
  260.  
  261. #define WINBL        8
  262. #define WINBR        8
  263. #define WINBB        8
  264. #define WINBT        32
  265.  
  266. #ifdef PARANOID
  267. #ifdef PROTO
  268. void *Realloc(void *p, long s);
  269. void *Alloc(long s);
  270. void Free(void *p);
  271. void PrintMemStats();
  272. #else
  273. void *Realloc();
  274. void *Alloc();
  275. void Free();
  276. #endif
  277. #else
  278. #define Realloc(p, s) realloc((p), (s))
  279. #define Alloc(s) malloc(s)
  280. #define Free(p) free(p)
  281. #endif
  282. #define SAFEFREE(p) if ((p)) {Free((p)); (p) = 0;}
  283.  
  284. /*Handy macros*/
  285. #ifndef MIN
  286. #define MIN(x, y)  ((x) < (y) ? (x) : (y))
  287. #endif
  288. #ifndef MAX
  289. #define MAX(x, y)  ((x) > (y) ? (x) : (y))
  290. #endif
  291. #ifndef ABS
  292. #define ABS(x) ((x) < 0 ? (-(x)) : (x))
  293. #endif
  294. #define MAG3(m) (sqrt((m)[0] * (m)[0] + (m)[1] * (m)[1] + (m)[2] * (m)[2]));
  295. #define NORM3(m) {float z7; z7 = 1.0 / MAG3(m); m[0] *= z7; m[1] *= z7; m[2] *= z7;}
  296. #define MATCOPY(d, s) {int i, j; for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) d[i][j] = s[i][j];}
  297. #define CROSS(A, B, C) (C)[0]=(A)[1]*(B)[2]-(A)[2]*(B)[1]; (C)[1]=(A)[2]*(B)[0]-(A)[0]*(B)[2]; (C)[2]=(A)[0]*(B)[1]-(A)[1]*(B)[0];
  298. #define DOT(A, B) ((A)[0] * (B)[0] + (A)[1] * (B)[1] + (A)[2] * (B)[2])
  299. #define NORMALIZE(A) {register double f; f = 1.0 / sqrt((A)[0]*(A)[0] + (A)[1]*(A)[1] +(A)[2]*(A)[2]); (A)[0] *= f;(A)[1]*=f; (A)[2]*=f;}
  300. #define REVERSE(A) (A)[0] = -(A)[0]; (A)[1] = -(A)[1]; (A)[2] = -(A)[2];
  301. #define VECCOPY(d, s) d[0] = s[0], d[1] = s[1], d[2] = s[2]
  302. #define BETWEENP(m, a, b) (((m) >= (a) && (m) <= (b)) || ((m) >= (b) && (m) <= (a)))
  303. #define MULTMATRIX(a, b, r)            \
  304.     (r)[0][0] = (a)[0][0]*(b)[0][0] + (a)[0][1]*(b)[1][0] + (a)[0][2]*(b)[2][0] + (a)[0][3]*(b)[3][0];\
  305.     (r)[1][0] = (a)[1][0]*(b)[0][0] + (a)[1][1]*(b)[1][0] + (a)[1][2]*(b)[2][0] + (a)[1][3]*(b)[3][0];\
  306.     (r)[2][0] = (a)[2][0]*(b)[0][0] + (a)[2][1]*(b)[1][0] + (a)[2][2]*(b)[2][0] + (a)[2][3]*(b)[3][0];\
  307.     (r)[3][0] = (a)[3][0]*(b)[0][0] + (a)[3][1]*(b)[1][0] + (a)[3][2]*(b)[2][0] + (a)[3][3]*(b)[3][0];\
  308.     (r)[0][1] = (a)[0][0]*(b)[0][1] + (a)[0][1]*(b)[1][1] + (a)[0][2]*(b)[2][1] + (a)[0][3]*(b)[3][1];\
  309.     (r)[1][1] = (a)[1][0]*(b)[0][1] + (a)[1][1]*(b)[1][1] + (a)[1][2]*(b)[2][1] + (a)[1][3]*(b)[3][1];\
  310.     (r)[2][1] = (a)[2][0]*(b)[0][1] + (a)[2][1]*(b)[1][1] + (a)[2][2]*(b)[2][1] + (a)[2][3]*(b)[3][1];\
  311.     (r)[3][1] = (a)[3][0]*(b)[0][1] + (a)[3][1]*(b)[1][1] + (a)[3][2]*(b)[2][1] + (a)[3][3]*(b)[3][1];\
  312.     (r)[0][2] = (a)[0][0]*(b)[0][2] + (a)[0][1]*(b)[1][2] + (a)[0][2]*(b)[2][2] + (a)[0][3]*(b)[3][2];\
  313.     (r)[1][2] = (a)[1][0]*(b)[0][2] + (a)[1][1]*(b)[1][2] + (a)[1][2]*(b)[2][2] + (a)[1][3]*(b)[3][2];\
  314.     (r)[2][2] = (a)[2][0]*(b)[0][2] + (a)[2][1]*(b)[1][2] + (a)[2][2]*(b)[2][2] + (a)[2][3]*(b)[3][2];\
  315.     (r)[3][2] = (a)[3][0]*(b)[0][2] + (a)[3][1]*(b)[1][2] + (a)[3][2]*(b)[2][2] + (a)[3][3]*(b)[3][2];\
  316.     (r)[0][3] = (a)[0][0]*(b)[0][3] + (a)[0][1]*(b)[1][3] + (a)[0][2]*(b)[2][3] + (a)[0][3]*(b)[3][3];\
  317.     (r)[1][3] = (a)[1][0]*(b)[0][3] + (a)[1][1]*(b)[1][3] + (a)[1][2]*(b)[2][3] + (a)[1][3]*(b)[3][3];\
  318.     (r)[2][3] = (a)[2][0]*(b)[0][3] + (a)[2][1]*(b)[1][3] + (a)[2][2]*(b)[2][3] + (a)[2][3]*(b)[3][3];\
  319.     (r)[3][3] = (a)[3][0]*(b)[0][3] + (a)[3][1]*(b)[1][3] + (a)[3][2]*(b)[2][3] + (a)[3][3]*(b)[3][3];
  320. #define MATBYVECTOR(a, b, r)            \
  321.     (r)[0] = (a)[0][0]*(b)[0] + (a)[0][1]*(b)[1] + (a)[0][2]*(b)[2] + (a)[0][3];\
  322.     (r)[1] = (a)[1][0]*(b)[0] + (a)[1][1]*(b)[1] + (a)[1][2]*(b)[2] + (a)[1][3];\
  323.     (r)[2] = (a)[2][0]*(b)[0] + (a)[2][1]*(b)[1] + (a)[2][2]*(b)[2] + (a)[2][3];
  324. #define SQUARE(x) ((x) * (x))
  325. #define SKIPBLANKS(s) while (*(s) && isspace(*(s))) ++(s)
  326. #define ZERO3(d) {(d)[0] = 0.0; (d)[1] = 0.0; (d)[2] = 0.0;}
  327. #define COPY3(d, s) {(d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2];}
  328. #define ADD3(d, s) {(d)[0] += (s)[0]; (d)[1] += (s)[1]; (d)[2] += (s)[2];}
  329. #define DIV3SC(d, s) {(d)[0] /= (s); (d)[1] /= (s); (d)[2] /= (s);}
  330. #define CONTROL(c) ((c) & 0x1F)
  331. #define INT3(s1, s2, q, d) {(d)[0] = (s1)[0] + (q) * ((s2)[0] - (s1)[0]);\
  332.                 (d)[1] = (s1)[1] + (q) * ((s2)[1] - (s1)[1]);\
  333.                 (d)[2] = (s1)[2] + (q) * ((s2)[2] - (s1)[2]);}
  334.  
  335. #define LOGE10    2.30259
  336.  
  337. #ifdef FMATH
  338. #define rsin(x) fsin(x)
  339. #define rcos(x) fcos(x)
  340. #define rtan(x) ftan(x)
  341. #define rasin(x) fasin(x)
  342. #define racos(x) facos(x)
  343. #define ratan(x, y) fatan(x, y)
  344. #define ratan2(x, y) fatan2(x, y)
  345. #define rsqrt(x) fsqrt(x)
  346. #define rlog10(x) (flog(x) / LOGE10)
  347. #define rpow(x, y) fpow(x, y)
  348. #define rfloor(x) floor((double) x)
  349. #define rceil(x) ceil((double) x)
  350. #else
  351. #ifdef MATHF
  352. #define rsin(x) sinf(x)
  353. #define rcos(x) cosf(x)
  354. #define rtan(x) tanf(x)
  355. #define rasin(x) asinf(x)
  356. #define racos(x) acosf(x)
  357. #define ratan(x, y) atanf(x, y)
  358. #define ratan2(x, y) atan2f(x, y)
  359. #define rsqrt(x) sqrtf(x)
  360. #define rlog10(x) (logf(x) / LOGE10)
  361. #define rpow(x, y) powf(x, y)
  362. #define rfloor(x) floorf(x)
  363. #define rceil(x) ceilf(x)
  364. #else
  365. #define rsin(x) sin(x)
  366. #define rcos(x) cos(x)
  367. #define rtan(x) tan(x)
  368. #define rasin(x) asin(x)
  369. #define racos(x) acos(x)
  370. #define ratan(x, y) atan(x, y)
  371. #define ratan2(x, y) atan2(x, y)
  372. #define rsqrt(x) sqrt(x)
  373. #define rlog10(x) (log(x) / LOGE10)
  374. #define rpow(x, y) pow(x, y)
  375. #define rfloor(x) floor(x)
  376. #define rceil(x) ceil(x)
  377. #endif
  378. #endif
  379.  
  380. #ifndef M_PI
  381. #define M_PI        3.14159265358979323846
  382. #define M_PI_2        1.57079632679489661923
  383. #define M_PI_4        0.78539816339744830962
  384. #endif
  385.  
  386. #define ISVOWEL(c) ((c) == 'a' || (c) == 'A' || (c) == 'e' || (c) == 'E' \
  387.         || (c) == 'i' || (c) == 'I' || (c) == 'o' || (c) == 'O' \
  388.         || (c) == 'u' || (c) == 'U')
  389.  
  390. #define SQ2     (1.414213562)
  391. #define SQ22    (.707106)
  392. #define SQ33    (.577735)
  393.  
  394. /*Have to define h_errno just in case*/
  395. extern int h_errno;
  396.  
  397. #ifdef PROTO
  398. int strcmp2(char *, char *);
  399. int strcmp3(char *, char *);
  400. #else
  401. int strcmp2();
  402. int strcmp3();
  403. #endif
  404.  
  405. /*Define heartbeat*/
  406. #ifdef CLK_TCK
  407. #define HEARTBEAT CLK_TCK
  408. #else
  409. #ifdef HZ
  410. #define HEARTBEAT HZ
  411. #else
  412. #define HEARTBEAT 60
  413. #endif
  414. #endif
  415.  
  416.